<?php

/**
 * Registration form
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @uses      ../controllers/helper/Builder.php A custom action helper to create elements
 * @version   $Id: RegisterForm.php 38 2009-02-18 17:12:39Z monzee $
 */
class User_RegisterForm extends Zend_Form
{
    public function init()
    {
        $builder = Zend_Controller_Action_HelperBroker::getStaticHelper('Builder');

        $whole = $this->_elemDecors('whole');
        $half = $this->_elemDecors('half');
        $third = $this->_elemDecors('third');
        $quarter = $this->_elemDecors('quarter');

        /* @var $builder User_Helper_Builder */
        $builder->setForm($this)

            ->decorators($half)
            ->options(array('class' => 'thick', 'required' => true))
            ->validators(array('StringLength', false, array(4)), 'Alnum')
                ->addText('userName', array('label' => 'Username', 'decorators' => $third))

            ->validators('EmailAddress')
                ->addText('email', array('label' => 'Email Address', 'decorators' => $whole))

            ->options(array('class' => 'text', 'required' => true))
            ->validators(array(array('StringLength', false, array(6,32))))
//            ->filters(array(array('Callback', 'md5'))) // zend_form_element_abstract uses
                                                         // filtered values during isValid(). grrr.
                ->addPassword('password', array('label' => 'Password'))
                ->addPassword('passwordConfirm', array('label' => 'Password confirmation', 'ignore' => true))
            ->endValidators()
//            ->endFilters()

            ->decorators($whole)
            ->options(array('class' => 'text', 'required' => false, 'ignore' => true))
                ->addText('hobbies', array('label' => 'Hobbies'))
                ->addSelect('alignment', array('label' => 'Alignment',
                    'multiOptions' => array('nice' => 'Lawful good', 'boring' => 'Neutral', 'badass' => 'Chaotic evil')))
                ->addRadio('preference', array('description' => 'STOP:', 'separator' => ' ',
                    'class' => 'radio', 'labelClass' => 'radio-label',
                    'decorators' => array('Description', 'ViewHelper', 'Errors'),
                    'multiOptions' => array('yes' => 'Hammertime', 'no' => 'Collaborate and listen', 'dunno' => 'go')))
                ->addTextarea('biography', array('label' => 'Biography'))

            ->decorators('File', 'Errors',
                array('Label', array('placement' => 'append')),
                array('HtmlTag', array('tag' => 'div', 'class' => 'whole')))
            ->setEnctype('multipart/form-data')
                ->addFile('upload', array('label' => 'Pics or it didn\'t happen.'))
                
            ->decorators('Captcha', 'Errors',
                array('Description', array('tag' => 'label', 'for' => 'captcha-input', 'placement' => 'prepend')))
            ->options(array('required' => true, 'ignore' => true))
                ->addCaptcha('captcha', array(
                    'description' => 'Please enter the letters you see below',
                    'captcha' => array('Figlet', 'wordLen' => 5),))

            ->options(array('class' => 'button', 'ignore' => true))
            ->decorators('ViewHelper')
              ->addSubmit('submit', array('label' => '  Okay  '));

    }

    protected function _elemDecors($wrapClass)
    {
        $class = strtolower($wrapClass) != 'whole' ? 'part ' . $wrapClass : $wrapClass;
        return array(
            'ViewHelper', 'Errors',
            array('Label', array('placement' => 'append')),
            array('HtmlTag', array('tag' => 'div', 'class' => $class))
        );
    }

}
